package edu.calvin.djs32.cs214.interpreters.prettyprinter;

import static org.junit.Assert.*;

import org.antlr.runtime.CommonToken;
import org.antlr.runtime.tree.CommonTree;
import org.junit.Before;
import org.junit.Test;

import edu.calvin.djs32.cs214.interpreters.frontend.Hobbes2008Parser;

public class PrettyPrinterTest {
	private PrettyPrinter myPrettyPrinter;
	
	private CommonTree createTree(int integer) {
	    return new CommonTree(new CommonToken(Hobbes2008Parser.INTEGER, String
	        .valueOf(integer)));
	}
	
	@Before
	public void setUp() {
		myPrettyPrinter = new PrettyPrinter();
	}
	
	@Test
	public void shouldPrettyPrintIntegers() {
	  assertEquals("<span class=\"integer\">123</span>", myPrettyPrinter.computeSpan(123));
	  assertEquals("<span class=\"integer\">253</span>", myPrettyPrinter.computeSpan(253));
	  assertEquals("<span class=\"integer\">83452</span>", myPrettyPrinter.computeSpan(83452));
	}
	
	@Test
	public void shouldPrettyPrintNegativeIntegers() {
	  assertEquals("<span class=\"integer negative\">-123</span>", myPrettyPrinter.computeSpan(-123));
	  assertEquals("<span class=\"integer negative\">-83452</span>", myPrettyPrinter.computeSpan(-83452));
	  assertEquals("<span class=\"integer negative\">-9999999</span>", myPrettyPrinter.computeSpan(-9999999));
	  assertEquals("<span class=\"integer negative\">-123456</span>", myPrettyPrinter.computeSpan(-123456));
	}
	
	@Test
	public void shouldPrettyPrintStrings() {
	  assertEquals("<span class=\"string\">&lsquo;foo&rsquo;</span>", myPrettyPrinter.computeSpan("'foo'"));
	  assertEquals("<span class=\"string\">&lsquo;foo bar&rsquo;</span>", myPrettyPrinter.computeSpan("'foo bar'"));
	  assertEquals("<span class=\"string\">&lsquo; &rsquo;</span>", myPrettyPrinter.computeSpan("' '"));
	}
	
	@Test
	public void shouldAddPreTags(){
		 assertEquals("<pre><span class=\"integer negative\">-123</span></pre>", myPrettyPrinter.interpret(createTree(-123)));
		 assertEquals("<pre><span class=\"integer\">123456</span></pre>", myPrettyPrinter.interpret(createTree(123456)));
	}
}
